﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace GDI_应用案例.Pages.Controls._3D
{
    public unsafe abstract class Draw3DBase: DisposableBase
    {
        private float _distance = 1200;
        /// <summary>
        /// 视点到投影平面的距离
        /// </summary>
        public float Distance
        {
            get { return _distance; }
            set
            {
                _distance = value;
            }
        }
        /// <summary>
        /// 视点位置，默认左上角
        /// </summary>
        public Point3D ViewpointPosition;
        public virtual RectangleF Bounds { get; }
        public abstract void Draw(Graphics g, Pen pen);

        public abstract void OnMouseDown(MouseEventArgs e);
        public abstract void OnMouseUp(MouseEventArgs e);
        public abstract void OnMouseMove(MouseEventArgs e);
        public abstract void OnMouseLeave(EventArgs e);
        public abstract void OnMouseWheel(MouseEventArgs e);

        protected T* AllocateT<T>(int count)
        {
            int size = sizeof(T) * count;
            IntPtr memoryPtr = Marshal.AllocHGlobal(size);
            return (T*)memoryPtr;
        }
        protected void FreeT<T>(T* ptr) => Marshal.FreeHGlobal((IntPtr)ptr);
    }
}
